package com.lanyun.controller;

import com.lanyun.pojo.*;
import com.lanyun.service.ProductService;
import com.lanyun.service.StockService;
import com.lanyun.service.WarehouseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 库存
 */
@Controller
public class StockController {

    @Autowired
    private StockService stockService;
    @Autowired
    private WarehouseService wareservice;
    @Autowired
    private ProductService proService;

    /*
        展示所有库存商品,以及条件查询下拉列表数据
     */
    @RequestMapping("/stockShowAll")
    public String StockInfo(Map<String,Object> map,Integer hous,Integer pro){
        //stocks 库存表所有的数据
        List<Stock>  stocks =  stockService.showStock(hous,pro);//条件查询,动态Sql实现
        List<Warehouse> House=wareservice.listAllw();//分组查询仓库,给下拉列表赋值
        List<Product>  pros  = proService.getAll();//分组查询商品,给下来列表赋值
        map.put("stocks",stocks);
        map.put("house",House);
        map.put("pros",pros);
        return "stock";
    }

    @RequestMapping("/stockshow")
    public String stockRe(Integer hous,Integer pro,Map map){
        List<Stock>  stocks =  stockService.showStock(hous,pro);
        map.put("stocks",stocks);
        return "stock::pageInfo";
    }

    /*
        相应Ajax 选择仓库后,动态设置商品下拉列表
     */
    @RequestMapping("/stockPro")
    @ResponseBody
    public Object showPro(@RequestParam("hous") Integer hous){
        //通过仓库id,查询商品
        List<Product>  pros = proService.gerProductByWarehouseId(hous);//相应Ajax 选择仓库后,动态设置商品下拉列表
        return pros;

    }
    /*
        库存变更记录
     */
    @RequestMapping("/stockInfo")
    public Object showStockInfon(Map map,Integer admin,String begin,String end,Integer Hous,Integer Pro,String type){
        //查询stockinfo表中所有数据
        List<Stockinfo> stockInfos = stockService.showStockInfo(admin,begin,end,Hous,Pro,type);

        //分组查询员工，商品，仓库，给库存变更记录界面下拉列表赋值
        List<Admin> admins = stockService.groupAdmin();
        List<Warehouse> warehouses = stockService.groupHous();
        List<Product> products = stockService.groupPro();
        map.put("admins",admins);
        map.put("stockInfos",stockInfos);
        map.put("warehouses",warehouses);
        map.put("products",products);
        return  "stockInfo";
    }

/*
    库存预警
 */
    @RequestMapping("/stockWarning")
    public Object warning(Map map){
        List<Map<String,Object>> lists = stockService.showWarning();
        map.put("lists",lists);
        return "stockWarning";
    }



}
